﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true"
    CodeFile="EditEmployees.aspx.cs" Inherits="Employees_EditEmployees" Title="Служители" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <h2 style="border-bottom: solid 1px black">
        <asp:Image ID="imgUsers" runat="server" Width="15" Height="15" ImageUrl="~/images/Profile.png" />&nbsp;&nbsp;Служители</h2>
    <asp:HiddenField ID="hfEmployeeID" runat="server" />
    <asp:MultiView ID="mvEmployees" runat="server">
        <asp:View ID="vEmployeeList" runat="server">
            <asp:GridView ID="gvEmployees" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" GridLines="Horizontal"
                AllowSorting="True" DataSourceID="ldsEmployee">
                <Columns>
                    <asp:TemplateField ShowHeader="False">
                        <ItemTemplate>
                            <asp:ImageButton ID="ibtnViewInfo" runat="server" CausesValidation="False" CommandName="ViewEmployeeInfo"
                                CommandArgument='<%# Eval("EmployeeID") %>' OnCommand="ibtnViewInfo_Command"
                                ImageUrl="~/images/Modify.png" Text="Select"></asp:ImageButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" ReadOnly="True" SortExpression="EmployeeID"
                        Visible="False" />
                    <asp:BoundField DataField="FirstName" HeaderText="Име" ReadOnly="True" 
                        SortExpression="FirstName" />
                    <asp:BoundField DataField="MiddleName" HeaderText="Презиме" ReadOnly="True" 
                        SortExpression="MiddleName" />
                    <asp:BoundField DataField="LastName" HeaderText="Фамилия" ReadOnly="True" 
                        SortExpression="LastName" />
                    <asp:BoundField DataField="Email" HeaderText="Email" ReadOnly="True" SortExpression="Email" />
                    <asp:BoundField DataField="JobTitle" HeaderText="Длъжност" ReadOnly="True" 
                        SortExpression="JobTitle" />
                    <asp:BoundField DataField="BusinessPhone" HeaderText="Телефон" ReadOnly="True"
                        SortExpression="BusinessPhone" />
                </Columns>
                <EmptyDataTemplate>
                    Липсват записи
                </EmptyDataTemplate>
                <HeaderStyle BackColor="#d2f1ad" />
                <RowStyle CssClass="grid_hover" />
            </asp:GridView>
            <asp:LinqDataSource ID="ldsEmployee" runat="server" ContextTypeName="EmployeeData.EmployeeDataClassesDataContext"
                EnableDelete="True" EnableInsert="True" EnableUpdate="True" Select="new (EmployeeID, FirstName, MiddleName, LastName, Email, JobTitle, BusinessPhone, HomePhone, FaxNumber, Address, City, StateProvince, PostalCode, Website, Notes)"
                TableName="Employees">
            </asp:LinqDataSource>
            <p style="margin-top: 8px;">
                <asp:HyperLink ID="lbtnAddEmployee" CssClass="link" NavigateUrl="~/Employees/CreateEmployee.aspx"
                    runat="server">
                    <asp:Image ID="imgAddEmployee" AlternateText="Нов служител" ImageAlign="Left" runat="server"
                        ImageUrl="~/images/Add.png" />
                    Нов служител</asp:HyperLink>
            </p>
        </asp:View>
        <asp:View ID="vEditEmployee" runat="server">
            <asp:DetailsView ID="dvEmployeeInfo" runat="server" AutoGenerateRows="False" DataKeyNames="EmployeeID"
                DataSourceID="ldsEmployeeInfo" CellPadding="3" Width="440px" OnItemDeleted="dvEmployeeInfo_ItemDeleted">
                <FieldHeaderStyle Width="150px" />
                <HeaderTemplate>
                    <label style="float: left;" class="insert_label">
                        <b>Данни за служителя</b></label><asp:ImageButton ID="ibtnClose" Style="float: right;"
                            ImageUrl="~/images/Delete.png" ToolTip="Затвори" Width="20" runat="server" CausesValidation="false"
                            OnClick="ibtnClose_Click" />
                </HeaderTemplate>
                <HeaderStyle BackColor="#99CCFF" />
                <EmptyDataTemplate>
                    Липсват записи
                </EmptyDataTemplate>
                <Fields>
                    <asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" InsertVisible="False"
                        ReadOnly="True" SortExpression="EmployeeID" Visible="False" />
                    <asp:TemplateField HeaderText="Име" SortExpression="FirstName">
                        <HeaderStyle CssClass="insert_label" />
                        <ItemTemplate>
                            <asp:Label ID="lblFirstName" runat="server" Text='<%# Eval("FirstName") %>'></asp:Label></ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbFirstName" MaxLength="50" CssClass="insert_input" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvFirstName" ValidationGroup="EmployeeInfo" ControlToValidate="tbFirstName"
                                ErrorMessage="Моля въведете име!" ToolTip="Моля въведете име!" runat="server">*</asp:RequiredFieldValidator>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Презиме" SortExpression="MiddleName">
                        <HeaderStyle CssClass="insert_label" />
                        <ItemTemplate>
                            <asp:Label ID="lblMiddleName" runat="server" Text='<%# Eval("MiddleName") %>'></asp:Label></ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbMiddleName" MaxLength="50" CssClass="insert_input" runat="server" Text='<%# Bind("MiddleName") %>'></asp:TextBox>
                            <%--<asp:RequiredFieldValidator ID="rfvMiddleName" ControlToValidate="tbMiddleName" ErrorMessage="Моля въведете презиме!"
                        ToolTip="Моля въведете презиме!" runat="server">*</asp:RequiredFieldValidator>--%>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Фамилия" SortExpression="LastName">
                        <HeaderStyle CssClass="insert_label" />
                        <ItemTemplate>
                            <asp:Label ID="lblLastName" runat="server" Text='<%# Eval("LastName") %>'></asp:Label></ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbLastName" MaxLength="50" CssClass="insert_input" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvLastName" ValidationGroup="EmployeeInfo" ControlToValidate="tbLastName"
                                ErrorMessage="Моля въведете фамилия!" ToolTip="Моля въведете фамилия!" runat="server">*</asp:RequiredFieldValidator>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Email" SortExpression="Email">
                        <HeaderStyle CssClass="insert_label" />
                        <ItemTemplate>
                            <asp:Label ID="lblEmail" runat="server" Text='<%# Eval("Email") %>'></asp:Label></ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbEmail" MaxLength="256" CssClass="insert_input" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvEmail" ControlToValidate="tbEmail" Display="Dynamic"
                                ErrorMessage="Моля въведете email!" ValidationGroup="EmployeeInfo" ToolTip="Моля въведете email!"
                                runat="server">*</asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="revEmail"
                                    runat="server" ControlToValidate="tbEmail" Display="Dynamic" ErrorMessage="Email полето е попълнено неправилно!"
                                    ToolTip="Email полето е попълнено неправилно!" ValidationGroup="EmployeeInfo"
                                    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Длъжност" SortExpression="JobTitle">
                        <HeaderStyle CssClass="insert_label" />
                        <ItemTemplate>
                            <asp:Label ID="lblJobTitle" runat="server" Text='<%# Eval("JobTitle") %>'></asp:Label></ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbJobTitle" MaxLength="50" CssClass="insert_input" runat="server" Text='<%# Bind("JobTitle") %>'></asp:TextBox>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Телефон" SortExpression="BusinessPhone">
                        <HeaderStyle CssClass="insert_label" />
                        <ItemTemplate>
                            <asp:Label ID="lblBusinessPhone" runat="server" Text='<%# Eval("BusinessPhone") %>'></asp:Label></ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbPhone" MaxLength="20" CssClass="insert_input" runat="server" Text='<%# Bind("BusinessPhone") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvPhone" ValidationGroup="EmployeeInfo" ControlToValidate="tbPhone"
                                ErrorMessage="Моля въведете телефон!" ToolTip="Моля въведете телефон!" runat="server">*</asp:RequiredFieldValidator>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Домашен тел." SortExpression="HomePhone">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" MaxLength="20" runat="server" Text='<%# Bind("HomePhone") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("HomePhone") %>'></asp:Label>
                        </ItemTemplate>
                        <ControlStyle CssClass="insert_input" />
                        <HeaderStyle CssClass="insert_label" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Факс" SortExpression="FaxNumber">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox2" MaxLength="20" runat="server" Text='<%# Bind("FaxNumber") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("FaxNumber") %>'></asp:Label>
                        </ItemTemplate>
                        <ControlStyle CssClass="insert_input" />
                        <HeaderStyle CssClass="insert_label" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Адрес" ControlStyle-CssClass="insert_input" SortExpression="Address">
                        <HeaderStyle CssClass="insert_label" />
                        <ItemTemplate>
                            <asp:Label ID="lblAddress" runat="server" Text='<%# Eval("Address") %>'></asp:Label></ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbAddress" MaxLength="100" runat="server" Text='<%# Bind("Address") %>'></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvAddress" ValidationGroup="EmployeeInfo" ControlToValidate="tbAddress"
                                ErrorMessage="Моля въведете адрес!" ToolTip="Моля въведете адрес!" runat="server">*</asp:RequiredFieldValidator>
                        </EditItemTemplate>
                        <ControlStyle CssClass="insert_input"></ControlStyle>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Град" SortExpression="City">
                        <HeaderStyle CssClass="insert_label" />
                        <ItemTemplate>
                            <asp:Label ID="lblCity" runat="server" Text='<%# Eval("City") %>'></asp:Label></ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbCity" MaxLength="50" CssClass="insert_input" runat="server" Text='<%# Bind("City") %>'></asp:TextBox>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Щат/Провинция" SortExpression="StateProvince">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox3" CssClass="insert_input" MaxLength="50" runat="server" Text='<%# Bind("StateProvince") %>'></asp:TextBox>
                        </EditItemTemplate>
                         <ItemTemplate>
                            <asp:Label ID="Label3" runat="server" Text='<%# Bind("StateProvince") %>'></asp:Label>
                        </ItemTemplate>
                        <HeaderStyle CssClass="insert_label" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Пощенски код" SortExpression="PostalCode">
                        <HeaderStyle CssClass="insert_label" />
                        <ItemTemplate>
                            <asp:Label ID="lblPostalCode" runat="server" Text='<%# Eval("PostalCode") %>'></asp:Label></ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbPostalCode" MaxLength="10" CssClass="insert_input" runat="server" Text='<%# Bind("PostalCode") %>'></asp:TextBox>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Уебсайт" SortExpression="Website">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox4" MaxLength="200" CssClass="insert_input" runat="server" Text='<%# Bind("Website") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("Website") %>'></asp:Label>
                        </ItemTemplate>
                        <HeaderStyle CssClass="insert_label" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Допълнителни бележки" SortExpression="Notes">
                        <HeaderStyle CssClass="insert_label" />
                        <ItemTemplate>
                            <asp:Label ID="lblNotes" runat="server" Text='<%# Eval("Notes") %>'></asp:Label></ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="tbNotes" MaxLength="300" CssClass="insert_input" TextMode="MultiLine" runat="server"
                                Text='<%# Bind("Notes") %>'></asp:TextBox>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField ShowHeader="False">
                        <ItemTemplate>
                            <div style="float: right;">
                                <asp:Button ID="btnEdit" ValidationGroup="EmployeeInfo" runat="server" CausesValidation="False"
                                    CommandName="Edit" Text="Редактирай" />
                                <asp:Button ID="btnDelete" ValidationGroup="EmployeeInfo" OnClientClick='javascript:return confirm("Сигурни ли сте, че искате да изтриете този служител?");'
                                    CommandName="Delete" runat="server" CausesValidation="False" Text="Изтрий" />
                            </div>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <div style="float: right;">
                                <asp:Button ID="btnUpdate" ValidationGroup="EmployeeInfo" runat="server" CausesValidation="True"
                                    CommandName="Update" Text="Обнови" />
                                &nbsp;<asp:Button ID="lbtnCancel" runat="server" CausesValidation="False" CommandName="Cancel"
                                    Text="Отказ" />
                            </div>
                        </EditItemTemplate>
                    </asp:TemplateField>
                </Fields>
            </asp:DetailsView>
            <asp:LinqDataSource ID="ldsEmployeeInfo" runat="server" ContextTypeName="EmployeeData.EmployeeDataClassesDataContext"
                EnableDelete="True" EnableUpdate="True" TableName="Employees" Where="EmployeeID == @EmployeeID">
                <WhereParameters>
                    <asp:ControlParameter ControlID="hfEmployeeID" Name="EmployeeID" PropertyName="Value"
                        Type="Int32" />
                </WhereParameters>
            </asp:LinqDataSource>
        </asp:View>
    </asp:MultiView>
</asp:Content>
